package com.qyhl.webtv.module_news.news.goodlife.detail;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.NormalNewsBean;
import com.qyhl.webtv.module_news.common.NewsUrl;
import com.qyhl.webtv.module_news.utils.NewsConstant;

/**
 * Created by qyhl on 2017/11/27.
 */

public class GoodLifeDetailModel implements GoodLifeDetailContract.GoodLifeDetailModel {
    private GoodLifeDetailPresenter mPresenter;

    public GoodLifeDetailModel(GoodLifeDetailPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 获取新趣汇详情
     *
     * @param newsId
     */
    @Override
    public void getData(String newsId) {
        String userName = CommonUtils.getInstance().getUserName();

        EasyHttp.get(NewsUrl.GET_LIFE_DETAILS)
                .params("userName", userName)
                .params("newsId", newsId)
                .execute(new SimpleCallBack<NormalNewsBean>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError(2, "暂无任何内容！");
                        } else {
                            mPresenter.setError(1, "数据解析异常，加载失败！");
                        }
                    }

                    @Override
                    public void onSuccess(NormalNewsBean normalNewsBean) {
                        mPresenter.setData(normalNewsBean);
                    }
                });
    }

    /**
     * 新趣汇详情统计
     *
     * @param newsId
     */
    @Override
    public void count(String newsId) {

        EasyHttp.get(NewsUrl.GET_NEWS_DETAIL_COUNT)
                .params("newsId", newsId)
                .params("tagName", NewsConstant.HSH_TAGNAME)
                .params("siteId", String.valueOf(NewsConstant.OWNER_SITE_ID))
                .execute(new SimpleCallBack<String>() {
                    @Override
                    public void onError(ApiException e) {

                    }

                    @Override
                    public void onSuccess(String s) {

                    }
                });
    }
}
